// 查询模板管理列表

import http from "@/api/config/http";
import { ENUM_DATA_SCOPE } from "@/enum/system.enum";
import { IQuery, IResponse, ITableResponse } from "@/interface/IAxios";
import { DragBox } from "@/views/admin/service/theme/board/data/types";
import { LcdGroup, LcdTheme, QueryTheme, ThemeCategory } from "./types";

export function queryTheme(query?: Partial<IQuery>) {
  return http.request<IResponse<QueryTheme[]>>({
    url: "/theme/template/query",
    method: "get",
    params: query
  });
}

export function listTheme(query?: Partial<IQuery>) {
  return http.request<ITableResponse<LcdGroup>>({
    url: "/theme/template/list",
    method: "get",
    params: query
  });
}

export const getTheme = (id: string) => {
  return http.request<IResponse<LcdTheme>>({
    url: `/theme/template/${id}`,
    method: "get"
  });
};

interface ThemeData {
  themeName: string;
  width: number;
  height: number;
  background: string;
  themeBoard: string;
  video?: any;
  image: DragBox[];
}

export const createTheme = (data: Partial<ThemeData>) => {
  return http.request({
    url: `/theme/template`,
    method: "post",
    data
  });
};
export const updateTheme = (data: Partial<ThemeData>) => {
  return http.request({
    url: `/theme/template`,
    method: "put",
    data
  });
};

export const deleteTheme = (ids: string[]) => {
  return http.request({
    url: `/theme/template/${ids.join(",")}`,
    method: "delete"
  });
};
export const selectSkin = (themeId: string, background: string) => {
  return http.request({
    url: `/theme/template/skin`,
    method: "post",
    data: {
      themeId,
      background
    }
  });
};
export const previewTheme = (goodsId: string, componentId: string): Promise<IResponse<string>> => {
  return http.request({
    url: `/theme/component/preview`,
    method: "get",
    params: {
      componentId,
      goodsId
    }
  });
};
export const themeFunc = (id: string) => {
  return http.request({
    url: `/theme/template/func/${id}`,
    method: "get"
  });
};
export const priority = (id: string) => {
  return http.request({
    url: `/theme/template/priority/${id}`,
    method: "get"
  });
};

interface CopyData {
  rename: string;
  copyList: string[];
}
export const copyTheme = (data: CopyData) => {
  return http.request({
    url: `/theme/template/copy`,
    method: "post",
    data
  });
};
export const delThemeGroup = (id: string) => {
  return http.request({
    url: `/theme/template/groups/${id}`,
    method: "delete"
  });
};
export const themeCategoryList = (query?: IQuery) =>
  http.request<ITableResponse<LcdTheme>>({
    url: `theme/category/list`,
    params: query
  });

export const themeCategoryTree = (scope: ENUM_DATA_SCOPE) =>
  http.request<IResponse<LcdTheme[]>>({
    url: `theme/category/tree`,
    method: "get",
    params: {
      scope,
      orderByColumn: "create_time",
      isAsc: "desc"
    }
  });

export const addThemeCategory = (data: ThemeCategory) =>
  http.request({
    url: `theme/category`,
    method: "post",
    data
  });

export const updateCategory = (data: ThemeCategory) =>
  http.request({
    url: `theme/category`,
    method: "put",
    data
  });

export const themeCategoryDetail = (id: string) => {
  return http.request({
    url: `theme/category/${id}`,
    method: "get"
  });
};

export const delThemeCategory = (id: string) => {
  return http.request({
    url: `theme/category/${id}`,
    method: "delete"
  });
};
